package org.hako.recite.word.tool;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * Result of kannji yomi analysis.
 * 
 * @since 0.4.14
 * @author <a href="mailto:xnnyygn@gmail.com">xnnyygn</a>
 */
public class KannjiYomiDetectResult implements Iterable<KannjiYomiPair> {

	public static final int ERROR_CODE_NONE = 0;
	public static final int ERROR_CODE_NO_KANNJI = 1;
	public static final int ERROR_CODE_FAILURE = 10;

	private int errorCode = ERROR_CODE_NONE;
	private List<KannjiYomiPair> pairs;
	private String kannjiWithYomi;
	private boolean omitThisWOrd;

	/**
	 * Create
	 * 
	 * @param errorCode
	 */
	public KannjiYomiDetectResult(int errorCode) {
		this(errorCode, false);
	}

	/**
	 * Create
	 * 
	 * @param errorCode
	 * @param omitThisWOrd
	 */
	public KannjiYomiDetectResult(int errorCode, boolean omitThisWOrd) {
		super();
		this.errorCode = errorCode;
		this.omitThisWOrd = omitThisWOrd;
	}

	/**
	 * Create
	 * 
	 * @param pair
	 * @param kannjiWithYomi
	 */
	public KannjiYomiDetectResult(KannjiYomiPair pair, String kannjiWithYomi) {
		this(Arrays.asList(pair), kannjiWithYomi);
	}

	/**
	 * Create
	 * 
	 * @param pairs
	 * @param kannjiWithYomi
	 */
	public KannjiYomiDetectResult(List<KannjiYomiPair> pairs,
			String kannjiWithYomi) {
		super();
		this.pairs = pairs;
		this.kannjiWithYomi = kannjiWithYomi;
		omitThisWOrd = false;
	}

	@Override
	public Iterator<KannjiYomiPair> iterator() {
		return pairs.iterator();
	}

	/**
	 * Get errorCode.
	 * 
	 * @return the errorCode
	 */
	public int getErrorCode() {
		return errorCode;
	}

	/**
	 * Get pairs.
	 * 
	 * @return the pairs
	 */
	public List<KannjiYomiPair> getPairs() {
		return pairs;
	}

	/**
	 * Get kannjiWithYomi.
	 * 
	 * @return the kannjiWithYomi
	 */
	public String getKannjiWithYomi() {
		return kannjiWithYomi;
	}

	/**
	 * Check if successful
	 * 
	 * @return
	 */
	public boolean isSuccess() {
		return errorCode == ERROR_CODE_NONE;
	}

	/**
	 * Get omitThisWOrd.
	 * 
	 * @return the omitThisWOrd
	 */
	public boolean isOmitThisWOrd() {
		return omitThisWOrd;
	}

	@Override
	public String toString() {
		return "KannjiYomiAnalyzeResult [errorCode=" + errorCode + ", pairs="
				+ pairs + ", kannjiWithYomi=" + kannjiWithYomi + "]";
	}

}
